package calorie.com.calorie.contact;


import com.lxh.baselibray.mvp.BasePresent;
import com.lxh.baselibray.mvp.IBaseView;
import com.lxh.baselibray.net.NetCallBack;
import com.lxh.baselibray.net.ServiceGenerator;


import calorie.com.calorie.api.ApiService;
import calorie.com.calorie.request.UpdateMoneyAddressRequest;
import calorie.com.calorie.request.UpdateNickNameRequest;
import calorie.com.calorie.request.UpdateReceivingAddressRequest;
import calorie.com.calorie.request.UpdateSexRequest;
import calorie.com.calorie.response.ResultDTO;
import retrofit2.Call;
import retrofit2.Response;
//修改个人信息
public class PersonalInfomationConstant extends BasePresent<PersonalInfomationConstant.IPersonInfo> {
    public static class PersonalInfomationPresent extends BasePresent<IPersonInfo> {


        public void updateNickName(String nickName, Integer userId) {
            UpdateNickNameRequest request = new UpdateNickNameRequest(userId, nickName);
            ApiService service = ServiceGenerator.createService(ApiService.class);
            service.updateNickName(request).enqueue(new NetCallBack<ResultDTO>() {
                @Override
                public void onSuccess(Call<ResultDTO> call, Response<ResultDTO> response) {
                    if (getView() != null) {
                        getView().getUpdateNickNameResult(response);
                    }
                }

                @Override
                public void onFailed() {

                }
            });
        }

        public void updateSex(String sex, Integer userId) {
            UpdateSexRequest request = new UpdateSexRequest(userId, sex);
            ApiService service = ServiceGenerator.createService(ApiService.class);
            service.updateSex(request).enqueue(new NetCallBack<ResultDTO>() {
                @Override
                public void onSuccess(Call<ResultDTO> call, Response<ResultDTO> response) {
                    if (getView() != null) {
                        getView().getUpdateSexResult(response);
                    }
                }

                @Override
                public void onFailed() {

                }
            });
        }

        public void updateReceivingAddress(String receivingAddress, Integer userId) {
            UpdateReceivingAddressRequest request = new UpdateReceivingAddressRequest(receivingAddress, userId);
            ApiService service = ServiceGenerator.createService(ApiService.class);
            service.updateReceivingAddress(request).enqueue(new NetCallBack<ResultDTO>() {
                @Override
                public void onSuccess(Call<ResultDTO> call, Response<ResultDTO> response) {
                    if (getView() != null) {
                        getView().getUpdateReceivingAddressResult(response);
                    }
                }

                @Override
                public void onFailed() {

                }
            });
        }
        public void updateMoneyAddress(String moneyAddress, Integer userId) {
            UpdateMoneyAddressRequest request = new UpdateMoneyAddressRequest( userId,moneyAddress);
            ApiService service = ServiceGenerator.createService(ApiService.class);
            service.updateMoneyAddress(request).enqueue(new NetCallBack<ResultDTO>() {
                @Override
                public void onSuccess(Call<ResultDTO> call, Response<ResultDTO> response) {
                    if (getView() != null) {
                        getView().getUpdateMoneyAddressResult(response);
                    }
                }

                @Override
                public void onFailed() {

                }
            });
        }
    }
    public interface IPersonInfo extends IBaseView {
        void getUpdateNickNameResult(Response<ResultDTO> response);

        void getUpdateSexResult(Response<ResultDTO> response);

        void getUpdateReceivingAddressResult(Response<ResultDTO> response);
        void getUpdateMoneyAddressResult(Response<ResultDTO> response);
    }
}
